import random

OriginalStr = 'MEET ME AT BIGTREE NINE AM'
# ord('A') -> 65
# ord('Z') -> 90
OriginalSeqList = [i for i in range(65,91,1)]
for i in range(0,len(OriginalSeqList),1):
    print(OriginalSeqList[i])
EncrytSeqList = OriginalSeqList.copy()
random.shuffle(EncrytSeqList)  #打乱


EncryptedStr = []
for i in range(0,len(OriginalStr),1):
    print(ord(OriginalStr[i]))
    if ord(OriginalStr[i]) >= 65 and ord(OriginalStr[i]) <= 90:
        OriginalIndex = ord(OriginalStr[i]) - 65
        Ascii = EncrytSeqList[OriginalIndex]
        EncryptedStr.append(chr(Ascii))
    else:
        EncryptedStr.append(OriginalStr[i])
    print(EncryptedStr[i])

print("The original  string is %s" % OriginalStr)
print("The encrypted string is %s" % "".join(EncryptedStr))

RestoredStr = []
for i in range(0,len(EncryptedStr),1):
    if ord(EncryptedStr[i]) >= 65 and ord(EncryptedStr[i]) <= 90:
        RestoredIndex = -1
        for j in range(0,len(EncrytSeqList),1):
            if EncrytSeqList[j] == ord(EncryptedStr[i]):
                RestoredIndex = j
                break
        assert(RestoredIndex != -1)
        Ascii = OriginalSeqList[RestoredIndex]
        RestoredStr.append(chr(Ascii))
    else:
        RestoredStr.append(OriginalStr[i])
print("The restored  string is %s" % "".join(RestoredStr))